package com.tutorial.bf;

import com.tutorial.bf.dao.UserDao;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationContextTest {
    // public static void main(String[] args) {
    //     // ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext-beans.xml");
    //     ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext-beans.xml");
    //     UserService userService = (UserService) context.getBean("userService");
    //     UserService userServiceDefault = (UserService) context.getBean("userServiceDefault");
    //     System.out.println("userService = " + userService);
    //     System.out.println("userServiceDefault = " + userServiceDefault);
    //     userServiceDefault.show();
    //     // 静态工厂方法实例化Bean
    //     UserDao userDao = (UserDao) context.getBean("userDao1");
    //     System.out.println("userDao = " + userDao);
    //     // 实力工厂方法实例化Bean
    //     UserDao userDao2 = (UserDao) context.getBean("userDao2");
    //     System.out.println("userDao = " + userDao2);
    //     // 实现FactoryBean规范延迟实例化Bean
    //     UserDao userDao3 = (UserDao) context.getBean("userDao3");
    //     System.out.println("userDao = " + userDao3);
    //
    //     context.close();
    // }

    // public static void main(String[] args) {
    //     System.setProperty("spring.profiles.active", "test");
    //     ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext-autowired.xml");
    //     UserService userService = (UserService) context.getBean("userService");
    //     UserService userService1 = context.getBean(UserService.class);
    //     UserService userService2 = context.getBean("userService", UserService.class);
    //     System.out.println("userService1 = " + userService1);
    //     System.out.println("userService2 = " + userService2);
    //     // UserService userService1 = (UserService) context.getBean("userService1");
    //     UserDao userDao1 = (UserDao) context.getBean("userDao1");
    //     userService.show();
    //     // System.out.println("userService1 = " + userService1);
    //     System.out.println("userDao1 = " + userDao1);
    // }

    public static void main(String[] args) throws Exception {
        // ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext-DateSource.xml");
        // DruidDataSource dataSource = (DruidDataSource) context.getBean("druidDataSource");
        // System.out.println("dataSource = " + dataSource);
        //
        //
        // // Class.forName("com.mysql.cj.jdbc.Driver");
        // // Connection connection = DriverManager.getConnection("", "", "");
        //
        // Object connection = context.getBean("connection");
        // System.out.println("connection = " + connection);
        // Object date = context.getBean("date");
        // System.out.println("date = " + date);
        //
        // String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        // System.out.println("format = " + format);
        // /*// 静态工厂方法方式
        // InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        // // 无参构造实例化+实例工厂方法（.build()）
        // SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);*/
        //
        // Object sqlSessionFactory = context.getBean("sessionFactoryBuilder");
        // System.out.println("sqlSessionFactory = " + sqlSessionFactory);

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext-l3-cache.xml");
        UserDao userDao = (UserDao) context.getBean("userDao");
        userDao.show();
        // Object userService = context.getBean(OtherBean.class);
        // System.out.println("userService = " + userService);
    }
}
